import { message } from 'antd';

import api from '../../api';

export const namespace = 'BatchManageM';

export default {
  namespace,
  state: {},
  effects: {
    // 触发任务
    *triggerTask({ payload, callback }, { call }) {
      try {
        const res = yield call(api.batchManageApi.getBatchDataApi, payload);
        if (res?.code == 0) {
          callback(res.data);
        } else {
          message.error(res?.msg ?? '跑批失败，请联系管理员！');
        }
      } catch (e) {
        console.log(e);
      }
    },
    // 查询状态
    *queryStatus({ payload, callback }, { call }) {
      try {
        const res = yield call(api.batchManageApi.queryStatusApi, payload);
        if (res?.code == 0) {
          callback(res.data);
        } else {
          message.error(res.msg);
        }
      } catch (e) {
        console.log(e);
      }
    },
  },

  reducers: {
    setState(state, { payload }) {
      return {
        ...state,
        ...payload,
      };
    },
  },
};
